class Solution {//leetcode438——找到字符串中所有字母异位词
public:
    vector<int> findAnagrams(string s, string p) {
        vector<int> ret;
        int n=p.size();
        int hash1[26];
        for(auto e:p){
            hash1[e-'a']++;
        }

        int hash2[26]={0};

        for(int left=0,right=0,count=0;right<s.size();right++){
            //进窗口
            char in=s[right];
            hash2[in-'a']++;
            if(hash2[in-'a']<=hash1[in-'a']) count++;
            //出窗口
            if(right-left+1>n){
                char out=s[left++];
                if(hash2[out-'a']<=hash1[out-'a']) count--;
                hash2[out-'a']--;
            }

            if(count==n) ret.push_back(left);
        }
        return ret;
    }
};